package store

import (
	"fmt"
	"trader/config"

	_ "github.com/go-sql-driver/mysql"
	"xorm.io/xorm"
)

func ConnectMysql(mysql config.Mysql) (engine *xorm.Engine) {
	var err error

	engine, err = xorm.NewEngine("mysql", mysql.ConnStr())
	if err != nil {
		panic(fmt.Errorf("init mysql err: %s", err))
	}

	err = engine.Ping()
	if err != nil {
		panic(fmt.Errorf("connect mysql err: %s", err))
	}

	return
}
